package ro.ubb.dataaccess.service.impl;

import javax.ejb.Stateless;
import javax.persistence.PersistenceException;
import javax.persistence.TypedQuery;

import ro.ubb.dataaccess.entities.Book;
import ro.ubb.dataaccess.exception.MyBbException;
import ro.ubb.dataaccess.service.DataAccessServiceBook;

@Stateless
public class DataAccessServiceBookEJB extends DataAccessServiceBase<Book> implements DataAccessServiceBook {

	private static final Class<Book> type = Book.class;

	protected DataAccessServiceBookEJB() {
		super(type);
	}

	public Book getByTitle(String title) throws MyBbException {
		TypedQuery<Book> query = em.createNamedQuery("Book.findByTitle", type);
		query.setParameter("title", title);
		try {
			return query.getSingleResult();
		} catch (PersistenceException pe) {
			throw new MyBbException(pe);
		}
	}

}
